<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" media="all" th:href="@{/admin/layui/css/layui.css}">
    <link rel="stylesheet" media="all" th:href="@{/admin/style/admin.css}">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form" id="layuiadmin-form"
     style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" th:value="${entity.id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" th:value="${entity.name}" lay-verify="required" placeholder="请输入名称"
                   autocomplete="off" class="layui-input" maxlength="20">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">编码</label>
        <div class="layui-input-block">
            <input type="text" name="code" th:value="${entity.code}" lay-verify="required" placeholder="请输入编码"
                   autocomplete="off" class="layui-input" maxlength="20">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="Y" title="启用">
            <input type="radio" name="status" value="N" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">备注</label>
        <div class="layui-input-block">
			<textarea type="text" name="remark" lay-verify="required" autocomplete="off"
                      class="layui-textarea" placeholder="请输入备注" maxlength="200" th:text="${entity.remark}"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限</label>
        <div class="layui-input-block">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="LAY-submit" id="LAY-submit">提交</button>
    </div>
</div>
</body>
<script th:src="@{/admin/layui/layui.js}"></script>
<script>
    layui.config({
        base: '/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , authTree: 'authTree' //主入口模块
    }).use(['index', 'form', 'authTree', 'admin'], function () {
        var $ = layui.$, form = layui.form, authTree = layui.authTree, admin = layui.admin;
        var status = '[[${entity.status}]]' == '' ? '1': '[[${entity.status}]]';
        var id = '[[${entity.id}]]' == '' ? '0': '[[${entity.id}]]';
        $("input:radio[value='" + status + "']").attr('checked', 'true');
        form.render('radio');

        //执行 Ajax 后重载
        admin.req({
            url: '/sys/menu/roleMenu/' + id
            , done: function (res) {
                var data = res.data;
                var trees = authTree.listConvert(data.list, {
                    primaryKey: 'id'
                    , startPid: "0"
                    , parentKey: 'pid'
                    , nameKey: 'name'
                    , valueKey: 'id'
                    , checkedKey: data.menuIds
                });
                authTree.render('#LAY-auth-tree-index', trees, {
                    inputname: 'menuIds[]',
                    layfilter: 'lay-check-auth',
                    autowidth: true,
                });
            }
        });
    })
</script>
</html>